package com.mingqijia.gassafety.webserver.service.workorder;

import com.baomidou.mybatisplus.extension.service.IService;
import com.mingqijia.gassafety.db.entity.Consumer;
import com.mingqijia.gassafety.db.entity.WorkOrderHistory;
import com.mingqijia.gassafety.db.entity.vo.WorkOrderAndSmartKitVO;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 工单记录表 服务类
 * </p>
 *
 * @author guoliang.lao
 * @since 2022-09-15
 */
public interface WorkOrderHistoryService extends IService<WorkOrderHistory> {
    /**
     * 申请工单的流水号前缀
     */
    public static final String WORK_ORDER_NO_PREFIX = "WO";
    /**
     * 根据工单号更新处理状态
     * @param orderNo
     * @param handleStatus 0:进行中 1:完成
     */
    void updateHandleStatus(String orderNo, Integer handleStatus, Date completedTime);

    /**
     * 根据工单号更新删除设备
     * @param orderNo
     * @param deviceId
     */
    void updateDeviceId(String orderNo,String deviceId,String spId);

    void insertHistory(WorkOrderHistory workOrderHistory);

    void deleteHistory(String orderNo,String deviceId,String spId);

    /**
     * 删除退货安装的设备未完成的工单记录
     * @param deviceId
     * @param subsCode
     * @param spId
     * @param workSystem
     */
    void deleteHistoryByReturn(String deviceId,String subsCode,String spId,Integer workSystem);

    /**
     * 获取pkid
     * @param imei
     * @return
     */
    WorkOrderHistory selectPkidByImei(String imei,String spId,Integer orderType,Integer orderChannel);

    /**
     * 获取pkid
     * @param imeiList
     * @return
     */
    List<WorkOrderHistory> queryPkidByImeis(List<String> imeiList,String spId,Integer orderType,Integer orderChannel);

    int queryCountByImeis(String imei, String spId);

    int queryCountByImeis(List<String> imei, String spId);

    /**
     * 根据报警id查询工单和smartKit数据
     * @param
     */
    List<WorkOrderAndSmartKitVO> selectWorkOrderAndSmartKitByRecordId(List<String> orderNo);

     void existWorkOrder(String subsCode, String spId);
    WorkOrderHistory selectByOrderNo(String orderNo);

    //根据工单编号批量查询
    List<WorkOrderHistory> queryByOrderNo(List<String> orderNos);

    /**
     * 获取设备最后使用的客户类型
     * @param spId
     * @param deviceIds
     * @return
     */
    Map<String,Integer> selectDeviceLastUseCustType(String spId, List<String> deviceIds);

    /**
     * 获取工单发起的客户类型
     *
     * @param consumer
     * @return
     */
    int getOrderLaunchCustType(Consumer consumer);

}
